/**
 * Created by djei on 2015-02-12.
 */
$("#configForm").submit(function(){
    $(".load_div").show();
    $(".tab_data").hide();
    $("pre").text("");
    var formdate= $(this).serialize();
    $.ajax({
        type: "POST",
        url: "generate",
        data:formdate,
        success: function(data){
            if(!data.flag){
                $("#tab_model pre").text(data.modelText);
                $("#tab_model a.btn_down").attr("href","down?path="+data.modelUrl);

                $("#tab_xml pre").text(data.xmlText);
                $("#tab_xml a.btn_down").attr("href","down?path="+data.xmlUrl);

                $("#tab_mapper pre").text(data.mapperText);
                $("#tab_mapper a.btn_down").attr("href","down?path="+data.mapperUrl);

                $("#tab_example pre").text(data.exampleText);
                $("#tab_example a.btn_down").attr("href","down?path="+data.exampleUrl);
               // loadCopy();
                $(".tab_data").show();
            }else{
                alert("失败"+data.errMsg);
            }
            $(".load_div").hide();

        }
    });
    return false;
});

function loadCopy(){
    var client = new ZeroClipboard( $("#tab_model pre")[0] );
    ZeroClipboard.focus(client);
    client.on( "ready", function( readyEvent ) {
        client.on( "aftercopy", function( event ) {
            alert("Copied text to clipboard: " + event.data["text/plain"] );
        } );
    } );
}